<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script crossorigin="anonymous"
        integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
        src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js"></script>
</head>

<body>
    <form action="#">
        <div>
            <label for="username"> 用户名</label>
            <input type="text" id="username">
        </div>
        <div>
            <label for="userpwd"> 密码</label>
            <input type="password" id="userpwd">
        </div>
        <div>
            <button type="button"> 登录</button>
        </div>
    </form>
</body>
<script>
      const loginBtn = document.querySelector('button')
        loginBtn.onclick = function(){
            const user_name = document.getElementById('username').value,
                    user_pwd = document.getElementById('userpwd').value;
            $.ajax({
                url:"http://127.0.0.1:7001/login",
                method:"post",
                data:{user_name,user_pwd},
                success:function(res){
                    if(res.code===0){
                        localStorage.setItem('mytoken',res.token)
                        history.go(-1)
                    }else{
                        alert(res.msg)
                    }
                }
            })
        }
</script>

</html>